home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10404 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Non arithmetic integer type.
  5. Date: 17 Mar 1996 08:45:32 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ihfjcINNss6@keats.ugrad.cs.ubc.ca>
  8. References: <4igp11$83a@airdmhor.gen.nz>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4igp11$83a@airdmhor.gen.nz>,
  12. Simon Hosie <gumboot@airdmhor.gen.nz> wrote:
  13.  >  I've been trying to create a data type that holds an int or intlike chunk
  14.  >of data that is incompatible with any other types (to generate errors if
  15.  >someone assumes that it's the same type as an int).. I've found that
  16.  >
  17.  >typedef struct { int Value; } TypeA;
  18.  >typedef struct { int ValueWithADifferentName; } TypeB;
  19.  >
  20.  >  makes two compatible types; a variable of TypeA can be assigned to a
  21.  >variable of TypeB without any warnings.. but
  22.  
  23. Your compiler has a gratuitous extension that allows for structural
  24. equivalence type checking.
  25.  
  26. In standard C, structures with a different tag name are different.  Structures
  27. declard with _no tag_ are always incompatible with each other and with other
  28. structures that have tags.
  29.  
  30. An assignment between TypeA and TypeB shouldn't even compile.
  31.  
  32.  >typedef struct { int Value; } TypeA;
  33.  >typedef struct { unsigned Value; } TypeB;
  34.  >
  35.  >  is incompatible, which is what I want and it works.. but what if I want
  36.  >three or more incompatible types?
  37.  
  38. Get a compiler that adheres to the standard, or find an option in your compiler
  39. to make it do so.
  40.  
  41. -- 
  42.  
  43.